#!/bin/bash

# 启动 nginx
# 启动springboot 日志服务器

nginx_home=/opt/module/nginx
app_home=/opt/gmall0521
app=logger-0.0.1-SNAPSHOT.jar
case $1 in
"start")
if [[ -z "`pgrep -f nginx`" ]]; then
    echo "在 hadoop162 启动 nginx"
    $nginx_home/sbin/nginx
else
    echo " nginx 已经启动无序重复启动...."
fi

for host in hadoop162 hadoop163 hadoop164  ; do
    echo "在 $host 启动日志服务器"
    ssh $host "nohup java -jar $app_home/$app 1>>$app_home/log.out 2>>$app_home/log.err &"
done

   ;;

"stop")
    echo "在 hadoop162 停止 nginx"
    $nginx_home/sbin/nginx -s stop
    for host in hadoop162 hadoop163 hadoop164  ; do
        echo "在 $host 停止日志服务器"
        ssh $host "jps | awk '/$app/ {print \$1}' |xargs kill -9"
done
   ;;


 *)
    echo "执行的姿势不对: "
    echo "log.sh start 启动日志采集服务器 "
    echo "log.sh stop  停止日志采集服务器 "
;;
esac


